home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994…tember: Reference Library / Dev.CD Sep 94.toast / Periodicals / develop / develop Issue 6 / develop 6 code / TCP / NewsWatcher / NewsWatcher 2.0d15 source / source / wind.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-30  |  3.6 KB  |  157 lines  |  [TEXT/KAHL]

  1. /*----------------------------------------------------------------------------
  2.  
  3.     wind.c
  4.  
  5.     This module handles the commands in the Windows menu.
  6.     
  7.     Portions copyright © 1990, Apple Computer.
  8.     Portions copyright © 1993, Northwestern University.
  9.  
  10. ----------------------------------------------------------------------------*/
  11.  
  12. #include "glob.h"
  13. #include "full.h"
  14. #include "menus.h"
  15. #include "resize.h"
  16. #include "util.h"
  17. #include "wind.h"
  18.  
  19.  
  20. /*    SetWindowNeedsZooming sets the "standard state" of a window to
  21.     (0,0,0,0). This forces the next ToggleZoom call to zoom the window 
  22.     out. This function should be called whenever the window contents change.
  23. */
  24.  
  25. void SetWindowNeedsZooming (WindowPtr wind)
  26. {
  27.     WStateData **stateHndl;
  28.     
  29.     stateHndl = (WStateData**)((WindowPeek)wind)->dataHandle;
  30.     SetRect(&(**stateHndl).stdState, 0, 0, 0, 0);
  31. }
  32.  
  33.  
  34. /*    ToggleZoom toggles the window zoomed state of the active window.
  35.     The window will only be grown as big as it needs to be to contain
  36.     all of the data.  Also, whichever monitor contains the majority of
  37.     the window will be the destination for the window.
  38. */
  39.  
  40. void ToggleZoom (WindowPtr wind)
  41. {
  42.     WStateData **stateHndl;
  43.     Rect windRect;
  44.     GrafPtr savePort;
  45.     
  46.     GetPort(&savePort);
  47.     SetPort(wind);
  48.     windRect = wind->portRect;
  49.     LocalToGlobal((Point*)&windRect.top);
  50.     LocalToGlobal((Point*)&windRect.bottom);
  51.     SetPort(savePort);
  52.     stateHndl = (WStateData **) ((WindowPeek)wind)->dataHandle;
  53.     if (EqualRect(&(**stateHndl).stdState,&windRect)) {
  54.         DoZoom(wind,inZoomIn);
  55.     } else {
  56.         DoZoom(wind,inZoomOut);
  57.     }
  58. }
  59.  
  60.  
  61. /*    ShowHideGroups hides/shows the main groups window.
  62. */
  63.  
  64. void ShowHideGroups (void)
  65. {
  66.     MenuHandle windMenu;
  67.  
  68.     windMenu = GetMHandle(kWindMenu);
  69.     if (gPrefs.groupWindowVisible) {
  70.         HideWindow(gFullGroupWindow);
  71.         RemoveWindMenu(gFullGroupWindow);
  72.         SetItem(windMenu, kShowHideFullItem, kShowText);
  73.     }
  74.     else {
  75.         if (gMustDoZoomOnShowFullGroupList)
  76.             if (!DoZoom(gFullGroupWindow, inZoomOut)) return;
  77.         gMustDoZoomOnShowFullGroupList = false;
  78.         ShowWindow(gFullGroupWindow);
  79.         AddWindMenu(gFullGroupWindow);
  80.         SetItem(windMenu, kShowHideFullItem, kHideText);
  81.         SelectWindow(gFullGroupWindow);
  82.     }
  83.     gPrefs.groupWindowVisible = !gPrefs.groupWindowVisible;
  84. }
  85.  
  86.  
  87. /*    RemoveWindMenu removes a window's title from the windows menu when the
  88.     window is closed, etc…
  89. */
  90.  
  91. void RemoveWindMenu (WindowPtr wind)
  92. {
  93.     short item;
  94.     Str255 name,itemString;
  95.     MenuHandle windMenu;
  96.     
  97.     if (!wind) return;
  98.     windMenu = GetMHandle(kWindMenu);
  99.     GetWTitle(wind, name);
  100.     for (item = kFirstWindOffset; item <= CountMItems(windMenu); item++) {
  101.         GetItem(windMenu,item,itemString);
  102.         if (EqualString(name, itemString, true, true)) {
  103.             DelMenuItem(windMenu, item);
  104.             return;
  105.         }
  106.     }
  107. }
  108.  
  109.  
  110. /*    AddWindMenu adds a window's title to the windows menu.
  111. */
  112.  
  113. void AddWindMenu (WindowPtr wind)
  114. {
  115.     Str255 name;
  116.     MenuHandle windMenu;
  117.     short len;
  118.     
  119.     if (!wind) return;
  120.     windMenu = GetMHandle(kWindMenu);
  121.     GetWTitle(wind, name);
  122.     len = *name;
  123.     if (len > 0 && name[1] == '-') {
  124.         /* if first char of window title is '-' prepend a space to avoid
  125.           menu divider line. */
  126.         if (len < 255) len++;
  127.         BlockMove(name+1, name+2, len-1);
  128.         *name = len;
  129.         name[1] = ' ';
  130.     }
  131.     InsMenuItem(windMenu, "\pnew item", kFirstWindOffset-1);
  132.     SetItem(windMenu, kFirstWindOffset, name);
  133. }
  134.  
  135.  
  136. /*    SelectWindMenu is called when a user selects an item from the windows
  137.     menu.  The selected window is brought to the front.
  138. */
  139.  
  140. void SelectWindMenu (short item)
  141. {
  142.     Str255 name,itemString;
  143.     WindowPtr wind;
  144.     
  145.     GetItem(GetMHandle(kWindMenu), item, itemString);
  146.     for (wind = FrontWindow(); 
  147.         wind != nil; 
  148.         wind = (WindowPtr)((WindowPeek)wind)->nextWindow)
  149.     {
  150.         GetWTitle(wind, name);
  151.         if (EqualString(name, itemString, true, true)) {
  152.             SelectWindow(wind);
  153.             return;
  154.         }
  155.     }
  156. }
  157.